const express = require("express");
const app = express();
const port = 8989;

//获取token
app.get("/getLogin", (req, res) => {
  if (req.query.user == "admin" && req.query.psd == "123456") {
    res.send({
      code: 200,
      data: {
        token: "admin_token",
        userInfo: "admin",
        btnPermission: ["add", "edit", "delete"],
      },
      msg: "登录成功",
    });
  } else if (req.query.user == "normal" && req.query.psd == "123456") {
    res.send({
      code: 200,
      data: {
        token: "normal_token",
        userInfo: "normal",
        btnPermission: ["add", "edit"],
      },
      msg: "登录成功",
    });
  } else {
    res.send({
      code: 500,
      msg: "用户名或密码错误",
    });
  }
});

//获取菜单
app.get("/getMenus", (req, res) => {
  if (req.query.role === "admin") {
    res.send({
      code: 200,
      data: ["Map", "Detail", "WangEdit", "ManyPackage"],
    });
  } else if (req.query.role === "normal") {
    res.send({
      code: 200,
      data: ["ManyPackage"],
    });
  } else {
    res.send({
      code: 500,
      data: [],
      msg: "此用户无权限",
    });
  }
});

app.listen(port, () => {
  console.log("服务器启动了");
});
